// pages/text/text.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sid: 0,
    info: {},
    advice: [],
    docinfo: {},
  },
  xiang:function(e){
    var docid = e.currentTarget.dataset.docid;
     wx.navigateTo({
       url: '../detail/detail?docId=' + docid,
     })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var sid = options.sid;
    this.setData({
      sid: sid,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var sid = that.data.sid;
    wx.request({
      url: app.api.hostUrl + '/Api/Supply/advice',
      method: 'post',
      data: {
        sid: sid,
        uid: app.api.userId,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var status = res.data.status;
        if (status == 1) {
          var info = res.data.info;
          var advice = res.data.advice;
          var docinfo = res.data.docinfo;
          that.setData({
            info: info,
            advice: advice,
            docinfo: docinfo,
          });
        } else {
          wx.showToast({
            title: '没有找到相关信息.',
            duration: 2000
          });
        }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      },
    })
  },

  reg: function (e) {
    var that = this;
    var content = e.detail.value.cb;
    if (!content) {
      wx.showToast({
        title: '您还没有输入回复内容！',
        duration: 2000
      });
      return false;
    }

    wx.request({
      url: app.api.hostUrl + '/Api/Supply/saveadvice',
      method: 'post',
      data: {
        sid: that.data.sid,
        content: content,
        uid: app.api.userId,
        thetype: 1,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var status = res.data.status;
        if (status == 1) {
          wx.showToast({
            title: '发送成功.',
            duration: 2000
          });
          setTimeout(function (e) {
            that.onShow();
          }, 2500);
        } else {
          wx.showToast({
            title: res.data.err,
            duration: 2000
          });
        }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      },
    })

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})